package ar.fiuba.tp7552.buildadmin.util;

import java.util.Calendar;
import java.util.Date;

public class CalendarUtil {
	
	
	public static Integer getYear(Date date) {
		Calendar ca1 = Calendar.getInstance();
		ca1.setTime(date);
        return ca1.get(Calendar.YEAR);
	}
	
	public static Integer getMonth(Date date) {
		Calendar ca1 = Calendar.getInstance();
		ca1.setTime(date);
        return ca1.get(Calendar.MONTH)+1;
	}

	public static Date addMonths(Date date, int months) {
		Calendar ca1 = Calendar.getInstance();
		ca1.setTime(date);
        ca1.add(Calendar.MONTH, months);
        return new Date(ca1.getTimeInMillis());
	}
	
	public static Date changeDay(Date date, int days) {
		Calendar ca1 = Calendar.getInstance();
		ca1.setTime(date);
        ca1.set(Calendar.DAY_OF_MONTH, days);
        return new Date(ca1.getTimeInMillis());
	}
	
	public static Date addOneMonth(Date date) {
		Calendar ca1 = Calendar.getInstance();
		ca1.setTime(date);
        ca1.add(Calendar.MONTH, 1);
        return new Date(ca1.getTimeInMillis());
	}
	
	public static Date createDate(Integer dia, Integer mes, Integer anio) {
		Calendar calendar = Calendar.getInstance();

		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		
		calendar.set(Calendar.DAY_OF_MONTH, dia);
		calendar.set(Calendar.MONTH, mes-1);
		calendar.set(Calendar.YEAR, anio);
		return new Date(calendar.getTimeInMillis());
	}
	
	public static Date createDate(Integer mes, Integer anio) {
		return createDate(1, mes, anio);
	}
	
	public static Date firstDateOfMonth(Date date) {
		Calendar ca1 = Calendar.getInstance();
		ca1.setTime(date);
        ca1.set(Calendar.DAY_OF_MONTH, 1);
        
        ca1.set(Calendar.HOUR_OF_DAY, 0);
        ca1.set(Calendar.MINUTE, 0);
        ca1.set(Calendar.SECOND, 0);
        ca1.set(Calendar.MILLISECOND, 0);
        
        return new Date(ca1.getTimeInMillis());
	}

}
